package vy.org.app.page.santsamaj;

/**
 * @author Ravi Shankar
 *
 */

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.vy.dal.dao.VySantSamajDAO;
import org.vy.dal.dao.VySantSamajDO;

import vy.org.app.common.AppConstants;
import vy.org.app.common.BaseAction;
import vy.org.app.common.ModeEnum;
import vy.org.app.common.ModuleEnum;
import vy.org.util.DateUtil;

public class MntnSantSamajAction extends BaseAction {

	@Override
	public ActionForward executeAction(ActionMapping mapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) {

		MntnSantSamajForm form = (MntnSantSamajForm) actionForm;
		VySantSamajDO dto = new VySantSamajDO();
		if (form != null && form.getMode() != null) {
			if (ModeEnum.SEARCH.getName().equals(form.getMode())) {

				dto = MntnSantSamajAssembler.getAssembler()
						.getSantSamajDO(form);
				try {
					request.setAttribute(AppConstants.RESULT, VySantSamajDAO
							.findByParam(dto));
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else if (ModeEnum.ADD.getName().equals(form.getMode())) {
				dto = MntnSantSamajAssembler.getAssembler()
						.getSantSamajDO(form);
				try {
					VySantSamajDAO.insert(dto);
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else if (ModeEnum.DELETE.getName().equals(form.getMode())) {
				dto = MntnSantSamajAssembler.getAssembler()
						.getSantSamajDO(form);
				try {
					VySantSamajDAO.delete(dto.getSantSamajId());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return mapping.findForward("success");
	}

	@Override
	protected ModuleEnum getModuleId() {
		return ModuleEnum.ADD_SANTSAMAJ;
	}

}
